package com.algorithm.tencent;

public class MostWater {
    public static void main(String[] args) {
        int[] arr = new int[]{1,5,2,7,3,6,9};
        System.out.println(maxArea(arr));
    }

    public static int maxArea(int[] arr){
        int i = 0;
        int j = arr.length -1;
        int maxRes = getArea(arr,i,j);
        while (i < j){
            int temp = 0;
            if (arr[i] < arr[j]){
                i++;
            }else {
                j--;
            }
            maxRes = Math.max(maxRes,getArea(arr,i,j));
        }
        return maxRes;
    }

    public static int getArea(int[] arr,int i,int j){
        return Math.min(arr[i],arr[j]) * (j - i);
    }
}
